package com.FH.applyFrom.salary_bill;

import com.FH.organization.Attachment.AttachmentPullDTO;
import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2017/8/14 0014.
 */
@Path("/salaryBill")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class SalaryBillResource {

    @EJB
    SalaryBillDAO salaryBillDAO;

    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getSalaryBillInfo(@PathParam("search")String search, @PathParam("page")String page, @PathParam("size")String size){
        //添加分页查询
        if(page==null||"".equals(page)){
            page = "1";//从第一页查起
        }
        if(size==null||"".equals(size)){
            size = "10";//默认每页10行
        }
        return salaryBillDAO.getSalaryBillInfo(search,page,size);
    }

    @GET
    @Path("/getSalary/{search}")
    public ResultDTO getSalaryInfo(@PathParam("search")String search){
        return salaryBillDAO.getSalaryInfo(search);
    }

    @POST
    @Path("/downloadExcel")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO downloadExcel(SalaryBillPullDTO salaryBillPullDTO){
        return salaryBillDAO.downloadExcel(salaryBillPullDTO);
    }

    /**
     * 解析导入的Excel表
     * @param
     * @return
     */
    @POST
    @Path("/poiExcel")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO poiExcel(AttachmentPullDTO attachmentPullDTO){
        return salaryBillDAO.poiExcel(attachmentPullDTO);
    }

    /**
     * 解析导入的自定义Excel工资表
     * @param
     * @return
     */
    @POST
    @Path("/poiSalaryExcel")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO poiSalaryExcel(AttachmentPullDTO attachmentPullDTO){
        return salaryBillDAO.poiSalaryExcel(attachmentPullDTO);
    }

    /**
     * 解析导入的自定义Excel工资表
     * @param
     * @return
     */
    @POST
    @Path("/importSalary")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO importSalaryInfo(SalaryInfoPullDTO salaryInfoPullDTO){
        return salaryBillDAO.importSalaryInfo(salaryInfoPullDTO);
    }

    /**
     * 批量添加工资条
     * @param salaryBillPullDTO
     * @return
     */
    @POST
    @Path("/addSalaryBillList")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addSalaryBillListInfo(SalaryBillPullDTO salaryBillPullDTO){
        return salaryBillDAO.addSalaryBillListInfo(salaryBillPullDTO);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addSalaryBillInfo(SalaryBillPullDTO salaryBillPullDTO){
        return salaryBillDAO.addSalaryBillInfo(salaryBillPullDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateSalaryBillInfo(SalaryBillPullDTO salaryBillPullDTO){
        return salaryBillDAO.updateSalaryBillInfo(salaryBillPullDTO);
    }

    @DELETE
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteSalaryBillInfo(SalaryBillPullDTO salaryBillPullDTO){
        return salaryBillDAO.deleteSalaryBillInfo(salaryBillPullDTO);
    }
}
